/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/system/io/platform/win32
// Copyright (c) 2014.  All Rights Reserved
//
// File:		AEWin32FileSystem.cpp
// Author:		Gianluca Belardelli
// Date:		11/10/2013
//
/////////////////////////////////////////////////////////////////////////
#include <AECore.h>
#include <core\system\io\platform\posix\AEPosixStreamReader.h>

typedef AEFileSystem::Result Result;

template<>AEFileSystem *AESingleton<AEFileSystem>::s_instance = NULL;

int initFileSystem()
{
	AEFileSystem::s_instance = new AEWin32FileSystem();
	return 0;
}

AERefNew<AEStreamReader> AEWin32FileSystem::OpenReader( const char *lpFileName, AEFileOpenFlags fofFlags )
{
	AEPosixStreamReader *defStreamReader = AEPosixStreamReader::Open( lpFileName );
		
	if( defStreamReader != NULL )
		return AERefNew<AEStreamReader>( new AEBufferedStreamReader( defStreamReader ) );

	return NULL;
}

//AERefNew<AEStreamWriter> AEWin32FileSystem::OpenWriter( const char *lpFileName, AEFileOpenFlags fofFlags = AE_OPEN_DEFAULT_WRITE );

Result AEWin32FileSystem::Remove( const char *lpPath )
{
	return RESULT_NOT_IMPLEMENTED;
}

Result AEWin32FileSystem::Mkdir( const char *lpPath )
{
	return RESULT_NOT_IMPLEMENTED;
}

Result AEWin32FileSystem::Stat( const char *lpPath, AEFileOrDirEntry &entryOut )
{
	//entryOut.SetPath( this, lpPath );

	return RESULT_NOT_IMPLEMENTED;
}
 
AERefNew<AEStreamReader> AEFileSystem::AEFileOrDirEntry::OpenReader( AEFileOpenFlags fofFlags  ) const
{
	AEPosixStreamReader *defStreamReader = AEPosixStreamReader::Open( this->m_lpPath );
		
	if( defStreamReader != NULL )
		return AERefNew<AEStreamReader>( new AEBufferedStreamReader( defStreamReader ) );

	return NULL;
}
